package com.atguigu.tingshu.album.api;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.BaseAttribute;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.model.album.BaseCategoryView;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jdk.jfr.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Tag(name = "分类管理")
@RestController
@RequestMapping(value="/api/album")
@SuppressWarnings({"all"})
public class BaseCategoryApiController {

	@Autowired
	private BaseCategoryService baseCategoryService;

	@Operation(summary="查所有的一二三级分类")
	@GetMapping(value = "/category/getBaseCategoryList")
	public Result<List<JSONObject>> getBaseCategoryList(){
		List<JSONObject> categoryList = baseCategoryService.getBaseCategoryList();
		return Result.ok(categoryList);
	}

	@Operation(summary="根据一级分类Id获取分类属性以及属性值")
	@GetMapping(value = "/category/findAttribute/{category1Id}")
	public Result<List<BaseAttribute>>  getAttributeByCategory1Id(@PathVariable Long category1Id){
		List<BaseAttribute> baseAttributeList = baseCategoryService.getAttributeByCategory1Id(category1Id);
		return Result.ok(baseAttributeList);
	}


	@Operation(summary = "根据三级分类Id 获取到分类信息")
	@GetMapping(value = "/category/getCategoryView/{category3Id}")
	public Result<BaseCategoryView> getCategoryView(@PathVariable Long category3Id){
		BaseCategoryView baseCategoryView = baseCategoryService.getCategoryView(category3Id);
		return Result.ok(baseCategoryView);
	}


	@Operation(summary = "根据一级分类Id查询三级分类列表")
	@GetMapping(value = "/category/findTopBaseCategory3/{category1Id}")
	public Result<List<BaseCategory3>> findTopBaseCategory3(@PathVariable Long category1Id){
		List<BaseCategory3> baseCategory3List = baseCategoryService.findTopBaseCategory3(category1Id);
		return Result.ok(baseCategory3List);
	}

	/**
	 * 根据1级分类ID查询包含二级分类以及三级分类
	 * @param category1Id
	 * @return
	 */
	@Operation(summary = "根据1级分类ID查询包含二级分类以及三级分类")
	@GetMapping("/category/getBaseCategoryList/{category1Id}")
	public Result<JSONObject> getBaseCategoryListByCategory1Id(@PathVariable Long category1Id){
		JSONObject jsonObject = baseCategoryService.getBaseCategoryListByCategory1Id(category1Id);
		return Result.ok(jsonObject);
	}

}

